package com.example.beat_x3.Client;

import java.io.BufferedOutputStream;
import java.io.ObjectInputStream;
import java.io.OutputStream;
import java.net.Socket;

import Entity.Inf;

public class Event {
    public static Object post(String postMessage, int port) {
        OutputStream out = null;
        ObjectInputStream in = null;
        Object res = null;
        try {
            Socket socket = new Socket(Inf.ip, port);
            socket.setSoTimeout(5000);
            out = new BufferedOutputStream(socket.getOutputStream());
            in = new ObjectInputStream(socket.getInputStream());
            out.write((postMessage).getBytes());
            out.flush();
            socket.shutdownOutput();
            res = in.readObject();
            System.out.println("end of connection");
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                out.close();
                in.close();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return res;
    }
}
